package com.szj.pet.hospital.service.impl;

import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.szj.pet.hospital.mapper.StaffMapper;
import com.szj.pet.hospital.model.hosp.Reserve;
import com.szj.pet.hospital.model.hosp.Staff;
import com.szj.pet.hospital.service.StaffService;
import com.szj.pet.hospital.vo.hosp.ReserveEeVo;
import com.szj.pet.hospital.vo.hosp.StaffEeVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@Service
public class StaffServiceImpl extends ServiceImpl<StaffMapper, Staff> implements StaffService {
    @Override
    public void exportStaffData(HttpServletResponse response) {
        //设置下载信息
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        String fileName = "staff";
        response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
        //查询数据库
        List<Staff> staffList = baseMapper.selectList(null);
        //Dict -- DictEeVo
        List<StaffEeVo> staffEeVoList = new ArrayList<>();
        for (Staff staff : staffList) {
            StaffEeVo staffEeVo = new StaffEeVo();
            // dictEeVo.setId(dict.getId());
            BeanUtils.copyProperties(staff, staffEeVo);
            staffEeVoList.add(staffEeVo);
        }
        //调用方法进行写操作
        try {
            EasyExcel.write(response.getOutputStream(), StaffEeVo.class).sheet("staff")
                    .doWrite(staffEeVoList);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    //导出数据字典接口

}
